<?php

class Workset_Sphinx_XmlPipe_Document extends Workset_Sphinx_XmlPipe_Entity {

    protected $_id = null;

    protected $_fields = array();

    public function __construct($id, array $fields) {
        $this->_id = (int)$id;
        $this->_fields = $fields;
    }

    public function toString() {
        $parts = array('<' . $this->_namespace . ':document id="'.$this->_id.'">');

        foreach ($this->_fields as $key => $value) {
            $parts[] = "\t<" . $key . '>' . $value . '</' . $key . '>';
        }

        $parts[] = '</' . $this->_namespace . ":document>\r\n";

        return implode("\r\n", $parts);
    }
    
}